package com.hrc.springbootdemo.ai;

import lombok.AllArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.model.openai.autoconfigure.OpenAiChatProperties;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AllArgsConstructor
public class AiConfiguration {
    private final   OpenAiChatModelFactory openAiChatModelFactory;

    @Bean
    public ChatClient ollamaChatClient(OllamaChatModel model) {
        return  ChatClient.builder(model)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultSystem("你是hrc_bot,是hrc开发的")
                .build();
    }


    /** 覆盖自动配置的，防止冲突*/
    @Bean
    public OpenAiChatModel openAiChatModel() {
        return openAiChatModelFactory.createChatModel(openAiChatProperties());
    }
    @Bean
    @ConfigurationProperties(prefix = "spring.ai.openai.chat")
    public OpenAiChatProperties openAiChatProperties() {
        return  new OpenAiChatProperties();
    }
    @Bean("openai")
    public ChatClient openAiChatClient(OpenAiChatModel model) {
        return  ChatClient.builder(model)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultSystem("你是hrc_bot,是hrc开发的")
                .build();
    }



    @Bean
    @ConfigurationProperties(prefix = "spring.ai.qiniu.chat")
    public OpenAiChatProperties qiniuChatProperties() {
        return  new OpenAiChatProperties();
    }
    @Bean("qiniu")
    public ChatClient qiniuChatClient() {
        OpenAiChatModel chatModel = openAiChatModelFactory.createChatModel(qiniuChatProperties());
        return  ChatClient.builder(chatModel)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultSystem("你是qiniu_chat_hrc_bot,是hrc开发的")
                .build();
    }

}
